import request from '@/src/basic/utils/request.js'
import { getUserInfo } from '@/src/basic/utils/user'

function handleParams(param) {
  let paramsUrl = ''
  for (const item in param) {
    let val = param[item]
    let str = `${item}=${val}&`
    paramsUrl += str
  }
  paramsUrl = paramsUrl.slice(0, paramsUrl.length - 1)
  return paramsUrl
}

export const loginOut = async () => {
  const info = getUserInfo()
  const { data } = await request.get(`/auth/logout/${info.refreshToken}`)
  return data
}

export const getStoreInformation = async params => {
  const { data } = await request.post(`/merchant/app/store/storeInformation`, params)
  return data
}

export const changeInformation = async params => {
  const { data } = await request.post(`${params}`)
  return data
}

export const findStoreAlbumList = async params => {
  const url = `/merchant/app/store/findStoreAlbumList?${handleParams(params)}`
  const { data } = await request.post(url)
  return data
}
export const updateStoreInformationAvatar = async params => {
  const url = `/merchant/app/store/updateStoreInformationAvatar?${handleParams(params)}`
  const { data } = await request.post(url)
  return data
}
export const submitStoreDetail = async params => {
  const url = `/merchant/app/store/submitStoreDetail?${handleParams(params)}`
  const { data } = await request.post(url)
  return data
}
export const submitStoreMoreAlbumUrls = async params => {
  // const url = `/merchant/app/store/submitStoreMoreAlbumUrls?${params}`
  const { data } = await request.post('/merchant/app/store/submitStoreMoreAlbumUrls', params)
  return data
}
export const deleteQictures = async params => {
  const url = `/basic/upload/deleteQictures?${handleParams(params)}`
  const { data } = await request.post(url)
  return data
}
// 商户-物联云商-APP反馈管理
export const submitFeedBack = async params => {
  const { data } = await request.post('/merchant/app/feedBack/submitFeedBack', params)
  return data
}
export const deleteStoreAlbumUrl = async params => {
  const { data } = await request.post(`/merchant/app/store/deleteStoreAlbumUrl?${handleParams(params)}`)
  return data
}
export const editStoreAlbum = async params => {
  const { data } = await request.post(`/merchant/app/store/editStoreAlbum?${handleParams(params)}`)
  return data
}
// 提交审批资料
export const submitStoreExamine = async params => {
  const { data } = await request.post('/merchant/app/store_exanime/submitStoreExamine', params)
  return data
}
// 提交审批资料
export const getExamineResult = async params => {
  const { data } = await request.post(`/merchant/app/store_exanime/getExamineResult?${handleParams(params)}`)
  return data
}
// /app/store/updateState更改营业状态  
export const updateState = async params => {
  const { data } = await request.post(`/merchant/app/store/updateState?${handleParams(params)}`)
  return data
}
// /app/store/updateByOperatingTime更改营业时间 
export const updateByOperatingTime = async params => {
  const { data } = await request.post(`/merchant/app/store/updateByOperatingTime?${handleParams(params)}`)
  return data
}
// /app/store/updatePerCapitaPrice更改人均价格、最低消费
export const updatePerCapitaPrice = async params => {
  const { data } = await request.post(`/merchant/app/store/updatePerCapitaPrice?${handleParams(params)}`)
  return data
}
// 获取标签详情
export const findAllTagByStore = async params => {
  const { data } = await request.get(`/merchant/app/tag/findAllTagByStore?${handleParams(params)}`)
  return data
}
// /app/tag/addShopTag根据店铺编号添加标签
export const addShopTag = async params => {
  const { data } = await request.post(`/merchant/app/tag/addShopTag?${handleParams(params)}`)
  return data
}
// /mcManagementType/businessType获取经营类型
export const businessType = async params => {
  const { data } = await request.post(`/merchant/mcManagementType/businessType?${handleParams(params)}`)
  return data
}
// /app/store/storeInformationById根据店铺id查看店铺信息
export const storeInformationById = async params => {
  const { data } = await request.post(`/merchant/app/store/storeInformationById?${handleParams(params)}`)
  return data
}
// /app/store/getAreaOrStreet获取商圈地区接口
export const getAreaOrStreet = async params => {
  const { data } = await request.get(`/merchant/app/store/getAreaOrStreet?${handleParams(params)}`)
  return data
}
// /merchant/changePasswordByOriginalPassword用密码修改密码
export const changePasswordByOriginalPassword = async params => {
  const { data } = await request.post(`/merchant/merchant/changePasswordByOriginalPassword?${handleParams(params)}`)
  return data
}
// /sms/send/free/vericode发送短信验证码
export const getCode = async phone => {
  const params = {
    phone: phone,
    loginType: 1
  }
  const { data } = await request.get('/basic/sms/send/free/vericode', params)
  return data
}
// /merchant/testOriginalPhone验证原手机
export const testOriginalPhone = async params => {
  const { data } = await request.post(`/merchant/merchant/testOriginalPhone?${handleParams(params)}`)
  return data
}
// /merchant/bindingOriginalPhone绑定新手机
export const bindingOriginalPhone = async params => {
  const { data } = await request.post(`/merchant/merchant/bindingOriginalPhone?${handleParams(params)}`)
  return data
}
// /app/store/saveManagementType店铺信息保存经营类型id
export const saveManagementType = async params => {
  const { data } = await request.post(`/merchant/app/store/saveManagementType?${handleParams(params)}`)
  return data
}
// /app/coupon/findMcCouponList查询到店卷列表
export const findMcCouponList = async params => {
  const { data } = await request.get(`/merchant/app/coupon/findMcCouponList?${handleParams(params)}`)
  return data
}
// /app/coupon/updShelfState 到店卷上下架
export const updShelfState = async params => {
  const { data } = await request.get(`/merchant/app/coupon/updShelfState?${handleParams(params)}`)
  return data
}